package com.vodone.v1pin.userInfo.delegate
{
	import com.vodone.v1pin.userInfo.vo.MailVO;
	
	import mx.collections.ArrayCollection;

	public class SystemMailUtil
	{
		public static function getSystemMailListFromObj(obj:Object , isSystem:Boolean):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection();
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.addItem(getMailItem(arr[i] , isSystem));
					}
				}
			}
			if(list && list.length > 0)
			{
				(list.getItemAt( list.length - 1 ) as MailVO).isLast = true;
				(list.getItemAt( 0 ) as MailVO).isOpen = true;
			}
			return list;
		}
		public static function getMailItem(obj:Object , isSystem:Boolean):MailVO
		{
			var item:MailVO = new MailVO();
			if(obj)
			{
				item.isSystem = isSystem;
				if(obj.hasOwnProperty("messageID"))
				{
					item.messageID = obj["messageID"];
				}
				if(obj.hasOwnProperty("content"))
				{
					item.content = obj["content"];
				}
				if(obj.hasOwnProperty("title"))
				{
					item.title = obj["title"];
				}
				if(obj.hasOwnProperty("createTime"))
				{
					item.createTime = obj["createTime"];
				}
				if(obj.hasOwnProperty("urlName"))
				{
					item.urlName = obj["urlName"];
				}
				if(obj.hasOwnProperty("url"))
				{
					item.url = obj["url"];
				}
			}
			return item;
		}
	}
}